import { defHttp } from '/@/utils/http/axios';
import {
  GetSpuListResultModel,
  SpuItem,
  baseSaleAttrListModel,
  GetSpuListParams,
  spuSaleAttrListModel,
  spuImageListModel,
} from './model/spuModel';

enum Api {
  GetSpuList = '/admin/product',
  SaveSpu = '/admin/product/saveSpuInfo',
  UpdateSpu = '/admin/product/updateSpuInfo',
  RemoveSpu = '/admin/product/deleteSpu',
  GetBaseSaleAttrList = '/admin/product/baseSaleAttrList',
  GetSpuImageListById = '/admin/product/spuImageList',
  GetSpuSaleAttrListById = '/admin/product/spuSaleAttrList',
}

/**
 * @description: 获取spu列表
 */
export function getSpuListApi({ page, limit, category3Id }: GetSpuListParams) {
  return defHttp.get<GetSpuListResultModel>({
    url: Api.GetSpuList,
    params: `/${page}/${limit}`,
    data: {
      category3Id,
    },
  });
}

/**
 * @description: 添加spu
 */
export function saveSpuApi(spu: SpuItem) {
  return defHttp.post<null>({
    url: Api.SaveSpu,
    data: spu,
  });
}

/**
 * @description: 修改spu
 */
export function updateSpuApi(spu: SpuItem) {
  return defHttp.post<null>({
    url: Api.UpdateSpu,
    data: spu,
  });
}

/**
 * @description: 删除spu
 */
export function removeSpuApi(spuId: number) {
  return defHttp.delete<null>({
    url: Api.RemoveSpu,
    params: `/${spuId}`,
  });
}

/**
 * @description: 获取spu基础销售属性列表
 */
export function getBaseSaleAttrListApi() {
  return defHttp.get<baseSaleAttrListModel>({
    url: Api.GetBaseSaleAttrList,
  });
}

/**
 * @description: 根据spuId获取spu销售属性列表
 */
export function getSpuSaleAttrListApi(spuId) {
  return defHttp.get<spuSaleAttrListModel>({
    url: Api.GetSpuSaleAttrListById,
    params: `/${spuId}`,
  });
}

/**
 * @description: 根据spuId获取spu图片列表
 */
export function getSpuImageListApi(spuId) {
  return defHttp.get<spuImageListModel>({
    url: Api.GetSpuImageListById,
    params: `/${spuId}`,
  });
}
